<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" name="" id="year" placeholder="请输入年份" />
    <button>验证</button>
  </body>
</html>
<script>
  var inp = document.querySelector("#year");
  var btn = document.querySelector("button");
  btn.onclick = function () {
    if (inp.value.trim() == "") return alert("请输入内容");
    if (isNaN(inp.value)) return alert("请输入数字");
    if (
      inp.value / 400 == "0" ||
      (inp.value % 4 == "0" && inp.value % 100 !== "0")
    ) {
      alert(inp.value + "是闰年");
    } else {
      alert(inp.value + "是平年");
    }
  };
</script>
